 <script type="text/javascript" src="<?php echo _RESOURCE_ROOT_PATH; ?>ckeditor/ckeditor.js" ></script>
 <!-- Example table --> <div class="container_12"> 
      <div class="module">
                     <h2><span>Add Wedding Package</span></h2>
                        
                     <div class="module-body">
                         <div style="margin-top:13px;">
                        <?php
                        if(isset($errMsg)){?>
                        <span class="notification"><?php echo $_MESSESGE[$errMsg];?></span>
                        <?php }?></div>
                        
                        <form name="admin_frm" id="admin_frm" action="" method="post" enctype="multipart/form-data">
                        
                            <p>                                
                                <label>Select Vendor</label>
                                <?php   
                                $vendor = Vendor::getVendor();
                                if( $vendor ){  
                                    echo '<select class="input-short" name="vendor" id="vendor_id">';
                                    echo '<option value="">Select Vendor</option>';
                                    $selval = $_POST['vendor'];
                                    foreach( $vendor as $row )  {
                                        $sel = $selval==$row['id'] ? 'selected' : '';
                                        echo '<option value="'.$row['id'].'" '.$sel.'>'.$row['name'].'</option>';
                                    }   
                                    echo '</select>';
                                }                                                        
                                ?>
                            </p>
                            <p>
                                <label>Fixed Cost Items</label>
                                <select class="input-short" name="fixed_cost_items[]" id="fixed_cost_items" multiple>
                                </select>
                            </p>
                            <p>
                                <label>Variable Cost Items</label>
                                <select class="input-short" name="variable_cost_items[]" id="variable_cost_items" multiple>
                                </select>
                            </p>
                            <p>
                                <label>Select Venue</label>
                                <select class="input-short" name="venue" id="venue_id">
                                    <option value="">Select Venue</option>
                                </select>
                            </p>
                            <p>
                                <label>Min Capacity</label>
                                <input type="text" class="input-short" name="min_capacity" id="min_capacity" value="0">
                            </p>
                            <p>
                                <label>Max Capacity</label>
                                <input type="text" class="input-short" name="max_capacity" id="max_capacity" value="0">
                            </p>
                            <p>
                                <label>Title<span class="star">*</span></font></label>
                                <div id="availability_info"></div>
								<input type="text" class="input-short check_availability" name="title" value="<?php echo $_POST['title'];?>" />
                                <!--  <span class="notification-input ni-correct">This is correct, thanks!</span> -->
                            </p>  
                            
                            <p>                                
                                <label>Select Theme<span class="star">*</span></label>
                                <?php   
                                $theme = Wedding::getThemeById();
                                if( $theme ){                                      
                                    echo '<select class="input-short" name="theme_id">';
                                    $selval = $_POST['theme_id'];
                                    foreach( $theme as $row )  {
                                        $sel = $selval==$row['id'] ? 'selected' : '';
                                        echo '<option value="'.$row['id'].'" '.$sel.'>'.$row['theme'].'</option>';
                                    }   
                                    echo '</select>';
                                }                                                        
                                ?>
                            </p>
                            
                            <!--<p>
                                <label>Package URL</label>
                                <input type="text" class="input-short" name="package_url" value="<?php echo $_POST['package_url'];?>" />
                            </p>-->
                            
                            <p>
                                <label>Number Of Days<span class="star">*</span></label>
                                <input style="width:50px;" type="text" class="input-short" id="number_of_days" name="number_of_days" value="<?php echo $_POST['number_of_days'];?>" />
                            </p>

                            <p>
                                <label>Wedding Days Specification</label>
                                <a href="javascript:void(0); " onclick="addSpecification(); " >Add Days Specification</a>
                                <div id="text"></div>
                                <div id="warning" style="color:#FF0000; "></div>

                            </p>
                                                        
                            <p>
                                <label>From Date</label>
                                <input name="from_date" type="text"  class="inputText" value="<?php echo $_POST['from_date']?>" size="10"/><a href="javascript:showCal('Calendar1')"><img src="<?php echo _SITE_ADMIN_URL_;?>images/calendar.jpg" alt="Click Here to Pick up the date" border="0" /></a>
                                <!-- <span class="notification-input ni-error">Sorry, try again.</span> -->
                            </p>
                            <p>
                                <label>To Date</label>
                                <input name="to_date" type="text"  class="inputText" value="<?php echo $_POST['to_date']?>" size="10"/><a href="javascript:showCal('Calendar2')"><img src="<?php echo _SITE_ADMIN_URL_;?>images/calendar.jpg" alt="Click Here to Pick up the date" border="0" /></a>
                                <!-- <span class="notification-input ni-error">Sorry, try again.</span> -->
                            </p>
                            
                            <p>
                                <label>Maximum Ceromonies<span class="star">*</span></label>
                                <input style="width:50px;" type="text" class="input-short" name="max_ceromonies" value="<?php echo $_POST['max_ceromonies'];?>" /><!-- <span class="notification-input ni-error">Sorry, try again.</span> -->
                            </p>
                            <p>
                                <label>Priority</label>
                                <input type="radio" name="priority" value="1" >True &nbsp;
                                <input type="radio" name="priority" value="0" checked>False
                            </p>
                            
                            <p>
                                <label>Tags</label>
                                <input type="text" class="input-short" name="tags" value="<?php echo $_POST['tags'];?>" /><!-- <span class="notification-input ni-error">Sorry, try again.</span> -->
                            </p>
                            
                            <!--<p>                                
                                <label>Slab</label>
                            <?php   
                                /*$packagetype = CommonUtility::getData(null, 'wedding_slab_master', array('status'=>'1'));
                                if( $packagetype ){  
                                    echo '<select class="input-short" name="slab_id">';
                                    $selval = $_POST['slab_id'];
                                    foreach( $packagetype as $row )  {
                                        $sel = $selval==$row['id'] ? 'selected' : '';
                                        echo '<option value="'.$row['id'].'" '.$sel.'>'.$row['title'].'</option>';
                                    }   
                                    echo '</select>';
                                }*/                                                       
                            ?>
                            </p> -->
                            <p>
                                <label>Base Price</label>                                
                                <input type="text" class="input-short" name="price" id="price" value="<?php echo $_POST['price'];?>">
                            </p>
                            <p>
                                <label>Person Allowed in Base Price</label>                                
                                <input type="text" class="input-short" name="no_of_people" id="no_of_people" value="<?php echo $_POST['no_of_people'];?>">
                            </p>
                            <p>
                                <label>Per Person Cost (When person exceed the base limit)</label>                                
                                <input type="text" class="input-short" name="per_person_cost" id="per_person_cost" value="<?php echo $_POST['per_person_cost'];?>">
                            </p>
                            
                            
                            <p>
                                <label>Discount</label>
                                <input type="text" class="input-short" name="discount" value="<?php echo $_POST['discount'];?>" />
                                <select class="input-short" name="discount_type">                                    
                                    <option value="1" <?php if($_POST['discount_type']=='1'){echo 'selected';}?> >Flat</option>
                                    <option value="2" <?php if($_POST['discount_type']=='2'){echo 'selected';}?> >Percent</option>
                                </select>
                                <!-- <span class="notification-input ni-error">Sorry, try again.</span> -->
                            </p>
                            
                            
                            <p>
                                <label>Short Description</label>
                                <textarea rows="7" cols="90" class="input-short" name="short_description"><?php echo $_POST['short_description'];?></textarea>                                
                            </p>
                            
                            <p>
                                <label>Description</label>
                                <!-- <textarea rows="7" cols="90" class="input-medium" name="description"><?php echo $_POST['description'];?></textarea> -->
                                <?php $editor->editor('description', $_POST['description']) ;?>
                            </p>
                                                        
                            <p>
                                <label>Booking Amount<span class="star">*</span></label>
                                <input type="text" class="input-short" name="booking_amount" value="<?php echo $_POST['booking_amount'];?>"  /><!-- <span class="notification-input ni-error">Sorry, try again.</span> -->
                            </p>
                            
                            <p>
                                <label>Cancellation Policy</label>
                                <textarea rows="7" cols="90" class="input-short" id="cancellation_policy" name="cancellation_policy"><?php echo $_POST['cancellation_policy']; ?></textarea>
                            </p>
                            <p>
                                <label>Terms & Conditions</label>
                                <textarea rows="7" cols="90" class="input-short" id="tc_policy" name="tc_policy"><?php echo $_POST['tc_policy']; ?></textarea>
                            </p>   

                            <p>
                                <label>Wedding Package Image</label>
                                <input type="file" name="package_image" />
                            </p>
                         
                            <p>
                                <label>Wedding Images (Site Gallery)</label>
                                <div id="wedding_images"></div>
                                <div id="wedding_images_warning"></div>
                                <input type="button" name="addImages" value="Add Wedding Images" onclick="addWeddingImages(); ">
                            </p>
                               
                            <fieldset>
                                <input class="submit-green" type="submit" name="submit" value="Submit" /> 
                               <input class="submit-gray" type="button" value="Cancel" onclick="javascript: window.location='<?php echo _SITE_ADMIN_URL_?>'+'wedding/wedding_mng.php';" />
                            </fieldset>
                        </form>
                     </div> <!-- End .module-body -->

                </div>  <!-- End .module -->
                </div>
                <div style="clear:both;"></div>

<script language="javascript">
addCalendar("Calendar1", "Select Date", "from_date", "admin_frm");
addCalendar("Calendar2", "Select Date", "to_date", "admin_frm");
setFormat("yyyy-mm-dd");
</script>                

<script type="text/javascript">
	var root_path = '<?php echo _SITE_ADMIN_URL_?>';
	var table = 'wedding_package';
	var field = 'title';
	
    fields = 0;
    var max_wedding_images = 20;
    function addWeddingImages() {
      if (fields < max_wedding_images) {
        var id = "file" + fields;
        $('#wedding_images').append( "<div style='padding:5px 0px; '><input type='file' name='wedding_images[]' />&nbsp;<input type='text' name='image_title[]' placeholder='Image Title' />&nbsp;<input type='text' name='image_tooltip[]' placeholder='Image Tooltip' />&nbsp;<input type='text' name='image_description[]' placeholder='Image Description' />" +
          " <a href='javascript:void(0); ' onclick='removeWeddingImages(this.parentNode)' >remove</a></div>");

        fields += 1;
      } else {
        document.getElementById('wedding_images_warning').innerHTML =
          "Only "+max_wedding_images+" wedding images allowed.";
        document.form.add.disabled = true;
      }
    }

    function removeWeddingImages( el ) {
      if (fields > 0) {
        document.getElementById('wedding_images_warning').innerHTML = "";
        var parent = document.getElementById('wedding_images');
        parent.removeChild(el);
        fields -= 1;
      }
    }

    fields_no_of_days = 0;
    var max_no_of_days = 0;
    function addSpecification() {
      max_no_of_days = $('#number_of_days').val();
      if(max_no_of_days == ''){
        alert('Please specify number of days first!');
        $('#number_of_days').focus();
        return false;
      }
      if (fields_no_of_days < max_no_of_days) {
        var id = "file" + fields_no_of_days;
        var venues_list = $('#venue_id').html();
        var text_to_be_appended = '<textarea id="wedding_specification'+fields_no_of_days+'" name="wedding_specification[]" /></textarea>';
        text_to_be_appended+='&nbsp;<select style="min-width:150px;" class="cbo_venues" name="cbo_venues[]" >'+venues_list+'</select>&nbsp;<input type="file" name="wedpg_days_image[]" >';
        text_to_be_appended+='&nbsp;<a href="javascript:void(0); " onclick="removeSpecification(this.parentNode)" >remove</a>';
        $('#text').append( '<div style="padding:5px 0px; ">'+text_to_be_appended+'</div>');
        CKEDITOR.replace('wedding_specification'+fields_no_of_days);
        fields_no_of_days += 1;
      } else {
        document.getElementById('warning').innerHTML =
          "Max "+max_no_of_days+" days specification allowed.";
        document.form.add.disabled = true;
      }
    }

    function removeSpecification( el ) {
      if (fields_no_of_days > 0) {
        document.getElementById('warning').innerHTML = "";
        var parent = document.getElementById('text');
        parent.removeChild(el);
        fields_no_of_days -= 1;
      }
    }

     function get_vendor_services(vendor_id){
        path = root_path+'ajax/getGeo.php?id='+vendor_id+'&type=vendor_services';
        $.ajax({url: path,  
            success: function(response) {
                $('#fixed_cost_items').html(response);
            }
        });
    }

    function get_all_services(){
        path = root_path+'ajax/getGeo.php?type=all_services';
        $.ajax({url: path,  
            success: function(response) {
                $('#variable_cost_items').html(response);
            }
        });
    }

    function get_vendor_tc_cancellation(_id){
        //var _id = $(this).val();
        path = root_path+'ajax/getGeo.php?id='+_id+'&type=tc_cancellation';
        $.ajax({url: path,  
            success: function(response) {
                var _response = response.split('##');
                var tc_policy = _response[0];
                var cancellation_policy = _response[1];
                $('#tc_policy').html(tc_policy);
                $('#cancellation_policy').html(cancellation_policy);
            }
        });
    }

	$().ready(function() {

        $('#vendor_id').change(function(){
            var vendor_id = $(this).val();
            path = root_path+'ajax/getGeo.php?id='+vendor_id+'&type=vendor_venue';
            $.ajax({url: path,  
                success: function(response) {
                    $('#venue_id').html(response);
                    get_vendor_services(vendor_id);
                    get_all_services();
                    get_vendor_tc_cancellation(vendor_id)
                }
            });
        });

        $('#venue_id').change(function(){
            var venue_id = $(this).val();
            path = root_path+'ajax/getGeo.php?id='+venue_id+'&type=venue_capacity';
            $.ajax({url: path,  
                success: function(response) {
                    var capacity = response.split('_');
                    $('#min_capacity').val(capacity[0]);
                    $('#max_capacity').val(capacity[1]);
                }
            });
            
        });

        /*$('#venue_id').change(function(){
            var _id = $(this).val();
            path = root_path+'ajax/getGeo.php?id='+_id+'&type=venue_tc_cancellation';
            $.ajax({url: path,  
                success: function(response) {
                    var _response = response.split('##');
                    var tc_policy = _response[0];
                    var cancellation_policy = _response[1];
                    $('#tc_policy').html(tc_policy);
                    $('#cancellation_policy').html(cancellation_policy);
                }
            });
        });*/

       $("#admin_frm").validate({
			rules: {
				vendor: "required",
				title: "required",
				theme_id: "required",
                min_capacity: {
                    required: true,
                    digits: true
                },
                max_capacity: {
                    required: true,
                    digits: true
                },            
				min_days: {
					required: true,
					digits: true
				},
				max_days: {
					required: true,
					digits: true
				},
				max_ceromonies: {
					required: true,
					digits: true
				},
				price: {
                    required: true,
                    number: true
                },
                no_of_people: {
                    required: true,
                    digits: true
                },
                per_person_cost: "number"            
			},
			messages: {
				vendor: "Please select the vendor",
				title: "Please enter title",            
				theme_id: "Please select theme",            
				min_days: "Please enter minimum number of days",
				max_days: "Please enter maximum number of days",
				max_ceromonies: "Enter max ceromonies",				            
				booking_amt: "Please enter booking amount",
				price: "Enter base price.",
                no_of_people: "Enter number of people allowed in base price.",
                per_person_cost: "Enter per person cost."             
			}
		});
	});
</script>       
<script type="text/javascript" src="<?php echo _ADMIN_JS_; ?>check_availability.js"></script>